package com.example.administrator.boxuegu.utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

public class SPreadOrWrite {

    public static void clearLoginStatus(Activity context){//清除登录状态
        SharedPreferences sharedPreferences=context.getSharedPreferences("loginInfo", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putBoolean("isLogin",false);
        editor.putString("loginUserName","");
        editor.commit();
    }

    public static boolean readLoginStatus(Activity context){//读取是否登录
        Boolean isLogin=false;
        SharedPreferences sharedPreferences=context.getSharedPreferences("loginInfo", Context.MODE_PRIVATE);
        isLogin=sharedPreferences.getBoolean("isLogin",false);
        return isLogin;
    }

    public static String readLoginName(Activity context){//读取登录的用户名
        SharedPreferences sharedPreferences=context.getSharedPreferences("loginInfo", Context.MODE_PRIVATE);
        return sharedPreferences.getString("loginUserName","");
    }

    public static void saveLoginStatus(Activity context,String name){//保存登录状态
        SharedPreferences sharedPreferences=context.getSharedPreferences("loginInfo", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putBoolean("isLogin",true);
        editor.putString("loginUserName",name);
        editor.commit();
    }
}
